function compareVersion(a, b) {
  const partsA = a.split(".").map(Number)
  const partsB = b.split(".").map(Number)

  const maxLength = Math.max(partsA.length, partsB.length)

  for (let i = 0; i < maxLength; i++) {
    const numA = partsA[i] || 0
    const numB = partsB[i] || 0
    if (numA > numB) return 1 // -1 降序
    if (numA < numB) return -1 // 1
  }
  return 0
}

function sortVersion(versions) {
  return versions.slice().sort(compareVersion) //.reverse()
}
const versions = ["1.2.3", "1.0.0", "2.0", "0.9.9", "1.10.0"]
console.log(sortVersion(versions))
// 降序： 方法一（修改比较函数）  return -1  return 1
//       方法二：反转结果       .reverse()
